<template>
  <div>
    <div style="color: red">
      检测数据类型 1.typeof用于检测基本数据类型 2.instanceof用于检测引用数据类型
    </div>
    <br />
    <div>基本数据类型：number,string,null,boolean,undefined</div>
    <br />
    <div>引用数据类型:Object,array,function,date</div>
    <br />

    <div>
      笔记:需要注意的是typeof如果检测的是引用数据类型全部返回的是object
      ,但是特殊的null返回的也是object,typeof检测function 和 Array 和
      Object,具有call方法的返回的都是function
    </div>
    <br />
    <div>typeof 返回的是类型 instanceof返回的是boolean</div>
    <br />
    <div>
      Object.prototype.toString.call()可以用来检测所有类型，并且返回类型
    </div>
  </div>
</template>

<script setup lang="ts">
const typeofFun = (value: any) => {
  return typeof value;
};
console.log(typeofFun("11")); //string
console.log(typeofFun(5)); //number
console.log(typeofFun(undefined)); //undefined
console.log(typeofFun(true)); //boolean

console.log(typeofFun(null)); //object

console.log(typeofFun([])); //object
console.log(typeofFun({})); //object
console.log(typeofFun(new Date())); //object

console.log(typeofFun(function () {})); //function
console.log(typeofFun(Array)); //function
console.log(typeofFun(Object)); //function
console.log(typeofFun(Function)); //function
console.log(typeofFun(String)); //function

console.log("@@@@@");

const str = "hello";
console.log(str);
console.log(typeof str); //string
const str1 = new String("hello");
const str2 = new Date();
console.log(str1); //String 实例化后的对象
console.log(typeof str2); //object
console.log(typeof str1); //object
console.log(typeof new Number(5.165156)); //object

console.log("@@@instanceof@@@@");

console.log([] instanceof Array); //true

console.log("@@@@toString.call()@@@@@");
const res = Object.prototype.toString.call("d").split(" ");

console.log("11", res[1]);
console.log(Object.prototype.toString.call([]));
console.log(Object.prototype.toString.call(undefined));
console.log(Object.prototype.toString.call(null));
console.log(Object.prototype.toString.call({}));
console.log(Object.prototype.toString.call(Array));
console.log(Object.prototype.toString.call(Function));
console.log(Object.prototype.toString.call(Object));
console.log(Object.prototype.toString.call(Date));
</script>

<style scoped lang="scss"></style>
